package com.itheima.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.pojo.CheckGroup;
import com.itheima.pojo.CheckItem;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface CheckGroupMapper extends BaseMapper<CheckGroup> {
    @Delete("delete from t_checkgroup_checkitem where CHECKGROUP_ID = #{groupId}")
    void relieveByGroupId(@Param("groupId") Integer groupId);

    @Select("SELECT tc.NAME " +
            "FROM  t_checkitem tc,t_checkgroup_checkitem tcgc " +
            "WHERE tc.id = tcgc.CHECKITEM_ID and tc.is_delete=0 AND tcgc.CHECKGROUP_ID =#{gid}")
    List<CheckItem> findCheckItemsByGroupId(@Param("gid") Integer gid);

    @Insert("insert into t_checkgroup_checkitem values(#{groupId},#{checkitemId})")
    void addCheckItemIdAndCheckGroupId(@Param("groupId") Integer groupId, @Param("checkitemId") Integer checkitemId);
}
